# try something like
@auth.requires_login()
def profile(): 
    try:
        userID = int(request.args[0])
        if len(request.args[0]) > 1 or userID <= 0 :
            raise Exception("Invalid Query") 
    except:
        userID = auth.user.id
   
    myUser = db((db.users.id==userID)&(db.users.foundationID==db.foundations.id)).select(db.users.id, db.users.username, db.users.first_name, db.users.last_name , db.users.registeredOn, db.users.email, db.users.mobile, db.users.faculty, db.users.department, db.users.grade, db.users.gender, db.users.isValid, db.foundations.name)
    
    if len(myUser):
        return dict(user=myUser)
        
def avatar():
    import os
    userID = int(request.args[0])
    userAvatar = db(db.users.id==userID).select(db.users.avatar)
    if not len(userAvatar) or not userAvatar[0].avatar:
        filename = os.path.join(request.folder, "static", "nophoto.png")
        return response.stream(filename)
    filename = os.path.join(request.folder, "uploads", userAvatar[0].avatar)
    return response.stream(filename)
